﻿
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>企业注册 -- 企业用户 --【赛码网】在线考试首选品牌</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <link rel="shortcut icon" href="~/Common/img/icon.svg" type="image/x-icon" />

    <link href="~/Common/css/jquery.cxdialog.css" rel="stylesheet" />
    <link href="~/Common/css/all-exam.css" rel="stylesheet" />
    <link href="~/Common/css/user/login.css" rel="stylesheet" />
    <!-- <link rel="stylesheet" type="text/css" href="/css/user/login2.css"> -->
</head>
<body>
    <!--head-->
    <div class="head">
        <div class="head-bar public">
            <div class="logo">
                <a href="/"><img src="https://kao.acmcoder.com/images/logo.png" /></a>
                <p><span>企业版</span></p>
            </div>
        </div>
    </div>
    <!--head  end-->
    <div class="acm-container" style="padding-bottom:200px;">
        <div class="userCnt">
            <div class="loginCnt">
                <h1>企业注册</h1>
                <div class="login-box">
                    <ul>
                        <li>
                            <span class="regisit-span">+86</span>
                            <input type="text" id="phone_ipt" class="login-text input regisit-phone" placeholder="请输入手机号" maxlength="11" />
                        </li>
                        <li>
                            <input type="text" id="vcode_ipt" class="login-text input regisit-send-input" placeholder="验证码" />
                            <a href="javascript:void(0)" class="regisit-send">获取验证短信</a>
                        </li>
                        <li>
                            <input type="password" id="pwd_ipt" class="login-text input" placeholder="请输入密码，至少6位" maxlength="20" />
                        </li>
                        <li>
                            <input type="password" id="pwd2_ipt" class="login-text input" placeholder="重复输入密码" />
                        </li>
                        <li class="login-t">
                            <span>
                                <input type="checkbox" id="ck_ipt" /> <label for="ck_ipt">我已阅读并同意<a href="javascript:void(0)" class="showxieyi">《赛码用户协议》</a></label>
                            </span>
                            <div class="clear"></div>
                        </li>
                        <li>
                            <span id="sbtn" class="login-btn btn" />提交注册</span>
                        </li>
                    </ul>
                </div>
                <div class="login-f">
                    已有账号，<a href="http://kao.acmcoder.com/enterprise/login">马上登录 >></a>
                </div>
            </div>
        </div>
    </div>
    <!--验证码弹窗-->
    <div id="verificationCode" class="none">
        <div class="verificationCode">
            <div class="verificationCode-img">
                <a href="javascript:void(0)"><img src="/vcode" id="vcode_img" onclick="refreshvCode()" /></a>
            </div>
            <input type="text" id="vcode_win_ipt" class="verificationCode-text" placeholder="请输入数字和字母" />
            <div class="clear"></div>
        </div>
    </div>
    <!--验证码弹窗 end-->
    <!--footer-->
    <!--footer end-->
    <script src="~/Common/js/jquery.min.js"></script>
    <script src="~/Common/js/jquery.cxdialog.js" type="text/javascript" charset="utf-8"></script>
    <script src="~/Common/js/all.js" type="text/javascript" charset="utf-8"></script>
    <script src="~/Common/js/user/regisit.js" type="text/javascript" charset="utf-8"></script>
    <script src="~/Common/js/common.min.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="https://cdn.acmcoder.com/static/1.0.1/js/jquery.cookie.js"></script>
    <script src="~/Common/js/footer-exam.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">
		window.alert = function(mess){
			$.cxDialog({
					  title: '提示',
					  info: '<div style="padding:20px;text-align:center;">' + mess + '</div>',
					  lockScroll: true,
					  background: '#000',
					  width:400,
					  okText:"我知道了",
					  ok: function(){
					  }
			});
			return false;
		}
		var clickLimitTime = 60;
		$(function(){
			var $phone_ipt = $('#phone_ipt'), $vcode_ipt = $('#vcode_ipt'), $pwd_ipt = $('#pwd_ipt'), $pwd2_ipt = $('#pwd2_ipt'), $ck_ipt = $('#ck_ipt');
			$('#sbtn').click(function(){
				var tosub = true;
				//提交校验
				if($.trim($phone_ipt.val())==''){
					tosub = false;
					setErrMsg($phone_ipt, '请输入手机号码');
				}else if( !checkMobile( $.trim( $phone_ipt.val() ) ) ){
					tosub = false;
					setErrMsg($phone_ipt, '手机号码格式不正确');
				}
				//if($.trim($vcode_ipt.val())==''){
				//	tosub = false;
				//	setErrMsg($vcode_ipt, '请输入验证码');
				//}else if(!checkVcode($.trim($vcode_ipt.val()))){
				//	tosub = false;
				//	setErrMsg($vcode_ipt, '验证码格式不正确');
				//}
				if($.trim($pwd_ipt.val())==''){
					tosub = false;
					setErrMsg($pwd_ipt, '请输入密码');
				}else if(!checkPwd($.trim($pwd_ipt.val()))){
					tosub = false;
					setErrMsg($pwd_ipt, '密码输入格式错误，至少6位');
				}
				if($.trim($pwd2_ipt.val())==''){
					tosub = false;
					setErrMsg($pwd2_ipt, '请重复输入密码');
				}else if( $.trim($pwd_ipt.val()) != $.trim($pwd2_ipt.val()) ){
					tosub = false;
					setErrMsg($pwd2_ipt, '两次输入密码不一致');
				}
				if(!$ck_ipt.is(':checked')){
					tosub = false;
					setErrMsg($ck_ipt, "请勾选同意《赛码用户协议》");
				}
				if (tosub) {
				    $.ajax({
				        url: "http://localhost:23975/api/show",
				        type: "post",
				        data: { phone: $phone_ipt.val(), pwd: $pwd_ipt.val() },
				        success: function (data) {
				            if(data>0)
				            {
				                alert("恭喜你注册成功");
				            }
				            else
				            {
				                alert("该用户名已被注册");
				            }
				        }
				    })
					//$.post('/enterprise/registers',{
					//	phone: $.trim($phone_ipt.val()),
					//	vcode: $.trim($vcode_ipt.val()),
					//	pwd: $.trim($pwd_ipt.val())
					//},function(json){
					//	if(json.success){
					//		if(json.msg!=''){
					//			window.location.href='/'+json.msg;
					//		}else{
					//			window.location.href='registerbymail';
					//		}

					//	}else if(json.type != null){
					//		if(json.type == 1){
					//			setErrMsg($phone_ipt, json.msg);
					//		}else if(json.type == 2){
					//			setErrMsg($vcode_ipt, json.msg);
					//		}else if(json.type == 3){
					//			setErrMsg($pwd_ipt, json.msg);
					//		}
					//	}else {
					//		alert(json.msg);
					//	}
				    //},'json');

				}
			});
			$('li input').keydown(function(){
				$(this).parent('li').removeClass('regisit-error');
				$(this).siblings('p').remove();
			});
			$ck_ipt.click(function(){
				if($ck_ipt.is(':checked'))$ck_ipt.siblings('p').remove();
			})
			$(".regisit-send").click(function(){
				if(!$(this).hasClass("disclick")){
					var status = verificationCodeWin();
				}
			});
		});
		var setErrMsg = function(_id, msg){
			if(_id.parent().find('p').length == 0)
				_id.parent().addClass('regisit-error').append('<p class="login-error "><i></i>' + msg + '</p>');
		}
		var checkMobile = function(str) {
		    var re = /^1\d{10}$/;
		    if (re.test(str))
		        return true;
		    else
		        return false;
		}
		var checkVcode = function(str) {
		    var re = /^\d{6}$/;
		    if (re.test(str))
		        return true;
		    else
		        return false;
		}
		var checkPwd = function(str) {
			var re = /^[a-zA-z0-9]\w{5,}$/;
		    if (re.test(str))
		        return true;
		    else
		        return false;
		}
		function
		 checkUser(str){
		    var re = /^[a-zA-z]\w{3,15}$/;
		    if(re.test(str)){
		        alert("正确");
		    }else{
		        alert("错误");
		    }
		}
		function
		 checkEmail(str){
		    var re = /^(\w-*\.*)+(\w-?)+(\.\w{2,})+$/;
		    if(re.test(str)){
		        alert("正确");
		    }else{
		        alert("错误");
		    }
		}
		var refreshvCode = function(t){
			var timestamp = new Date().getTime();
			timestamp = timestamp.toString();
			$('#vcode_img').attr('src', '/vcode?v=' + timestamp.base64Encode());
			$('#vcode_win_ipt').val('');
		}
		var verificationCodeWin = function(){
			if($.trim($('#phone_ipt').val())==''){
				setErrMsg($('#phone_ipt'), '请输入手机号码');
				return false;
			}else if( !checkMobile( $.trim( $('#phone_ipt').val() ) ) ){
				setErrMsg($('#phone_ipt'), '手机号码格式不正确');
				return false;
			}else{
				//$(document).unbind("keydown");
				/*$("#vcode_win_ipt").unbind("keydown").bind('keydown',function(event){
					if(event.keyCode == 13){ //绑定回车
						verificationCode();
						$.cxDialog.close();
						$("#pwd2_ipt,#pwd_ipt,#vcode_ipt").unbind("keydown").bind("keydown",function(event){
							if(event.keyCode == 13)
								$('#sbtn').click();
						});
					}
				});*/
				//$.cxDialog({
				//	  title: '验证码',
				//	  info: $("#verificationCode"),
				//	  lockScroll: true,
				//	  background: '#000',
				//	  width:350,
				//	  okText:"确认",
				//	  ok: function(){
				//		  verificationCode();
				//		  return false;
				//	  }
				//});
				/* var status2 = verificationCode();
				return status2; */

			}


		}

		$(document).keydown(function(event){
			if(event.keyCode == 13)
				$('#sbtn').click();
		});
		var verificationCode = function(){

			$.post('/enterprise/registervcode',{
				vcode: $.trim($('#vcode_win_ipt').val()),
				phone: $.trim($('#phone_ipt').val())
			},function(json){
				if(json.success){
					$(".regisit-send").html("短信发送成功！");
					if(!$(".regisit-send").hasClass("disclick")){
						$(".regisit-send").addClass("disclick");
						var debugTimer = window.setInterval(function () {
	                        if (clickLimitTime > 0) {
	                            $(".regisit-send").html("获取验证短信（" + clickLimitTime + "秒）");
	                            clickLimitTime--;
	                        } else {
	                            $(".regisit-send").html("获取验证短信").removeClass("disclick");
	                            window.clearInterval(debugTimer);
	                            clickLimitTime = 60;
	                        }
						}, 1000);
					}
					$.cxDialog.close();
					refreshvCode();
				}else{
					alert(json.msg);
				}
				refreshvCode();
			},'json');
		}

    </script>
</body>
</html>
